// 全局pop-up API工具（基于Vuex）
class PopUpAPI {
	constructor(store) {
		this.store = store;
	}
	
	// 显示消息提示
	show(options = {}) {
		this.store.dispatch('showPopup', options);
	}
	
	// 显示成功消息
	success(title, tip = '', url = '', timeout = 3000) {
		this.show({
			title: title,
			tip: tip,
			url: url,
			timeout: timeout
		});
	}
	
	// 显示错误消息
	error(title, tip = '', url = '', timeout = 5000) {
		this.show({
			title: title,
			tip: tip,
			url: url,
			timeout: timeout
		});
	}
	
	// 显示警告消息
	warning(title, tip = '', url = '', timeout = 4000) {
		this.show({
			title: title,
			tip: tip,
			url: url,
			timeout: timeout
		});
	}
	
	// 显示信息消息
	info(title, tip = '', url = '', timeout = 3000) {
		this.show({
			title: title,
			tip: tip,
			url: url,
			timeout: timeout
		});
	}
	
	// 关闭弹窗
	close() {
		this.store.dispatch('hidePopup');
	}
}

// 在Vue原型上挂载
export function install(Vue, store) {
	const popupAPI = new PopUpAPI(store);
	Vue.prototype.$popup = popupAPI;
}